﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace System.Data
{
    public class Repository<T> : IRepository<T> where T : EntityBase
    {
        private readonly IDbContext _context; 
        private IDbSet<T> _entities;
        protected virtual IDbSet<T> Entities
        {
            get { return _entities ?? (_entities = _context.Set<T>()); }
        }
        public Repository(IDbContext context)
        {
            _context = context;
        }
        public  T Find(params object[] keyValues)
        {
            return Entities.Find(keyValues);
        }
        public T FirstOrDefault(Expression<Func<T, bool>> predicate)
        {
            return Entities.FirstOrDefault(predicate);
        }
        public IQueryable<T> SelectQuery(string query, params object[] parameters)
        {
            throw new NotImplementedException();
        }

        public void Insert(T entity)
        {
            _context.Set<T>().Add(entity);
        }

        public void InsertRange(IEnumerable<T> entities)
        {
            throw new NotImplementedException();
        }

        public void InsertGraph(T entity)
        {
            throw new NotImplementedException();
        }

        public void InsertGraphRange(IEnumerable<T> entities)
        {
            throw new NotImplementedException();
        }

        public void Update(T entity)
        {
            throw new NotImplementedException();
        }

        public void Delete(object id)
        {
            throw new NotImplementedException();
        }

        public void Delete(T entity)
        {
            throw new NotImplementedException();
        }


        public Task<T> FindAsync(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        public Task<T> FindAsync(Threading.CancellationToken cancellationToken, params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        public Task<bool> DeleteAsync(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        public Task<bool> DeleteAsync(Threading.CancellationToken cancellationToken, params object[] keyValues)
        {
            throw new NotImplementedException();
        }
    }
}
